package plantshop.tests;

import static org.junit.Assert.*;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import plantshop.model.Display;
import plantshop.model.DisplayIterator;
import plantshop.model.plants.Aster;
import plantshop.model.plants.BurningBush;
import plantshop.model.plants.Plant;
import plantshop.model.plants.WhiteOak;

public class DisplayIteratorTest
{
	Display d;
	DisplayIterator iter;
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception
	{
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception
	{
	}

	@Before
	public void setUp() throws Exception
	{
		
	}

	@After
	public void tearDown() throws Exception
	{
	}

	@Test
	public void testHasNext()
	{
		d = new Display(10, 400, 400, true, 1, 1);
		Plant aster = new Aster();
		Plant burningBush = new BurningBush();
		Plant whiteOak = new WhiteOak();
		d.addPlant(0, aster);
		d.addPlant(1, aster);
		d.addPlant(2, burningBush);
		d.addPlant(4, whiteOak);
		d.addPlant(5, burningBush);
		iter = (DisplayIterator) d.iterator();
		assertTrue(iter.hasNext());
		
		d = new Display(10, 400, 400, true, 1, 1);
		iter = (DisplayIterator) d.iterator();
		assertFalse(iter.hasNext());
		
		d = new Display(10, 400, 400, true, 1, 1);
		iter = (DisplayIterator) d.iterator();
		d.addPlant(9, aster);
		assertTrue(iter.hasNext());
	}

	@Test
	public void testNext()
	{
		d = new Display(10, 400, 400, true, 1, 1);
		Plant aster = new Aster();
		Plant burningBush = new BurningBush();
		Plant whiteOak = new WhiteOak();
		d.addPlant(0, aster);
		d.addPlant(1, aster);
		d.addPlant(2, burningBush);
		d.addPlant(4, whiteOak);
		d.addPlant(5, burningBush);
		iter = (DisplayIterator) d.iterator();
		
		assertEquals(aster, iter.next());
		assertEquals(aster, iter.next());
		assertEquals(burningBush, iter.next());
		assertEquals(null, iter.next());
		assertEquals(whiteOak, iter.next());
		assertEquals(burningBush, iter.next());
		
		d = new Display(10, 400, 400, true, 1, 1);
		iter = (DisplayIterator) d.iterator();
		d.addPlant(9, aster);
		iter.hasNext();
		assertEquals(aster, iter.next());
	}

	@Test
	public void testRemove()
	{
		d = new Display(10, 400, 400, true, 1, 1);
		iter = (DisplayIterator) d.iterator();
		try
		{
			iter.remove();
			fail("No exception thrown");
		}
		catch (UnsupportedOperationException e)
		{
			assertTrue(e instanceof UnsupportedOperationException);
		}
	}

}
